str1 = input("输入一串字符串")
if str1.isdigit():
    file = "test_file/a.txt"
    with open(file, mode="w", encoding="utf-8") as f:
        f.write(str1)
else:
    print("输入内容有误")
